# extends 'base.html'
# import 'macro/forms.html' as forms
# import 'macro/utils.html' as utils


# block content
  <div class="page-header">
    <h1>
      {{utils.back_link('Back to user list', 'user_list', order='-modified')}}
      {{title}}
    </h1>
  </div>
  <div class="row">
    <div class="col-lg-12">
      <div class="table-responsive">
        <table class="table table-bordered table-hover">
          <thead>
            <tr class="text-nowrap">
              <th class="col-xs-3">Name</th>
              <th class="col-xs-2">Username</th>
              <th class="col-xs-2">Email</th>
              <th class="col-xs-2">Created <span class="fa fa-chevron-up text-muted"></span></th>
              <th class="col-xs-3">Permissions</th>
              <th class="text-center" title="Accounts"><span class="fa fa-key"></span></th>
            </tr>
          </thead>
          <tbody>
            # for user_db in user_dbs
              <tr id="{{user_db.key.urlsafe()}}" class="user-row {{'success' if merged_user_db.key.urlsafe() == user_db.key.urlsafe() else 'danger'}}">
                <td>
                  <input type="radio" name="user_db" value="{{user_db.key.urlsafe()}}" {{'checked' if merged_user_db.key.urlsafe() == user_db.key.urlsafe()}} disabled>
                  <img src="{{user_db.avatar_url_size(36)}}" width="18" alt="Avatar of {{user_db.name}}">
                  {{user_db.name}}
                  # if current_user.id == user_db.key.id()
                    <span class="fa fa-hand-o-left" title="You"></span>
                  # endif
                </td>
                <td>{{user_db.username}}</td>
                <td>{{user_db.email}}</td>
                <td>
                  <time datetime="{{user_db.created}}">
                    {{user_db.created.strftime('%Y-%m-%d')}}
                  </time>
                </td>
                <td>
                  # if user_db.admin
                    <span class="label label-danger"><span class="fa fa-cog"></span> admin</span>
                  # endif
                  # if not user_db.active
                    <span class="label label-default"><span class="fa fa-ban"></span> inactive</span>
                  # endif
                  # for permission in user_db.permissions
                    <span class="label label-info">{{permission}}</span>
                  # endfor
                </td>
                <td class="text-nowrap">{{utils.auth_icons(user_db)}}</td>
              </tr>
            # endfor
          </tbody>
        </table>
      </div>
    </div>
  </div>
  <hr>
  <form method="POST" action="." novalidate>
    <div class="row">
      <div class="col-md-6">
        {{form.csrf_token}}
        {{forms.hidden_field(form.user_keys)}}
        {{forms.hidden_field(form.user_key)}}
        {{forms.hidden_field(form.username)}}

        {{forms.text_field(form.username, disabled=True)}}
        {{forms.text_field(form.name)}}
        {{forms.email_field(form.email)}}
      </div>
      <div class="col-md-6">
        <div class="form-group">
          <label class="control-label">Merged Accounts</label>
          <table class="table table-bordered table-hover">
            <thead>
              <tr>
                <th><span class="fa fa-fw fa-key"></span></th>
                <th class="col-xs-12">Auth ID</th>
              </tr>
            </thead>
            <tbody>
              # for auth_id in auth_ids
                <tr>
                  <td>{{utils.auth_icon(auth_id)}}</td>
                  <td>{{auth_id}}</td>
                </tr>
              # endfor
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <div class="alert alert-warning">
      <ul>
        <li>Select the user's entity that you want to keep (the other entities will be deactivated)</li>
        <li>Before merging make sure the entities with references to the user are being taking care of</li>
        <li>For deactivated users the 3rd party associated accounts will be cleared</li>
      </ul>
    </div>
    <hr>
    <div class="row">
      <div class="col-md-6 col-md-offset-3">
        <button type="submit" class="btn btn-danger btn-lg btn-block btn-loading" {{forms.data_loading_text()}}>
          Merge
        </button>
      </div>
    </div>
  </form>
# endblock
